package com.drug.mingkang.controller;
import com.drug.mingkang.mapper.RecordMapper;
import com.drug.mingkang.model.Record;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.RecordService;
import com.drug.mingkang.utils.ResponseMessage;
import com.drug.mingkang.utils.Tools;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * (Record)表控制层
 *
 * @author ll
 * @since 2020-08-30 21:45:21
 */
@RestController
@RequestMapping("record")
public class RecordController {
    /**
     * 服务对象
     */
    @Resource
    private RecordService recordService;

    ResponseMessage responseMessage = new ResponseMessage();

    @Resource
    RecordMapper   mapper ;
    /**
     * 通过主键查询单条数据
     *
     * @param  informId
     * @return 显示发布出去的记录
     */
    @PostMapping("selectOne")
    public Record selectOne(String informId) {
        return this.recordService.queryById(informId);
    }

    //  查询全部
    @RequestMapping("selectAll")
    public Map<String,Object> selectAll(Record record, HttpSession session){
        PerUsers oper = (PerUsers) session.getAttribute("perUsers");
        List<Record> list = this.recordService.queryAllByLimit(record ,oper.getUserName());
        int  count =  mapper.count();     // 不显示行数
        Tools tools = new Tools();
        return tools.limit(list,count);
    }


    /**
     * 删除
     */
    @RequestMapping("delect")
    public ResponseMessage delete(String id){

        int rows = recordService.deleteById(id);

        if (rows>0){
            responseMessage.setStatus(1);
            responseMessage.setMessage("删除成功");
        }else {
            responseMessage.setStatus(0);
            responseMessage.setMessage("删除失败");
        }
        return responseMessage;
    }


}